#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include "d435Camera.h"
#include "cameraThread.h"
#include <iostream>
#include <QTimer>
#include <QTime>
#include "RobotInterface.hpp"
#include "calibthread.h"
#include <QMutex>

QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

    void handleFrame(const QImage &image);
    void timerSlot();
    void handleRMS(double rms);
    void handleMatrix(std::vector<double> matrix);
    void handleIntrinsic(std::vector<double> intrinsic);

    void onhandleCapture();
    void onhandleCalib();

private slots:
    void on_pb_capture_clicked();

    void on_pb_calib_clicked();

    void on_pb_reset_clicked();

    void on_pb_start_clicked();

private:
    int captureNum;
    Ui::MainWindow *ui;
    CameraThread* m_cameraThread;
    QMutex m_mutex;

    QImage tempQImage;
    QTimer *timer;
    std::string m_eliteIP;
    std::unique_ptr<RobotInterface> robot;   // 创建机器人接口实例
    std::vector<double> m_tcp;

    std::vector<cv::Mat> m_calibImages;
    std::vector<std::vector<double>> m_calibPoses;
    calibThread* m_calibThread;

    std::ostringstream m_folderName;
    std::ofstream m_posesFile;
    std::string m_posesPath;

    std::string m_cameraModel;
    void configReadMessage();

};
#endif // MAINWINDOW_H
